package com.demo.design.creational.prototype;

import java.util.ArrayList;
import java.util.List;

public class PrototypeCloneDemo implements Cloneable{

    private List<String> list = new ArrayList<>();

    /**
     * 深克隆
     */
//    @Override
//    public PrototypeCloneDemo clone() {
//        PrototypeCloneDemo newInstance = new PrototypeCloneDemo();
//        newInstance.list = this.list;
//        return newInstance;
//    }

    /**
     * 浅克隆
     * @return
     */
    @Override
    public Object clone() {
        PrototypeCloneDemo prototypeCloneDemo = null;
        try {
            prototypeCloneDemo = (PrototypeCloneDemo) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return prototypeCloneDemo;
    }

    public static void main(String[] args) {
        PrototypeCloneDemo prototypeCloneDemo = new PrototypeCloneDemo();
        PrototypeCloneDemo prototypeCloneDemo1 = (PrototypeCloneDemo) prototypeCloneDemo.clone();
    }
}
